﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using NPOI.HSSF.UserModel;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using NPOI.SS.Util;

namespace ConsoleApplication3
{
    class EachClassWithStudents
    {
        public List<Student> student;
        public string type; // 物理选 化学学……
    }

    class CountStu
    {
        public Student student;
        public int num;
    }

    class Classes
    {
        public static int MaxInAClass = 56;
        public const int MAXSTUDENT = 56;
        public string type;
        public int typeid;
        public List<Student> students = new List<Student>();
    }

    class xiaoleiherenshu
    {
        public int renshu;
        public int xiaolei;
        public Boolean flag;
    }

    class Student
    {
        public static int AllStudentNum = 0;
        public static string[] TypeName = { 
                                             "物理_化学_生物", "物理_化学_政治", "物理_化学_历史", "物理_化学_地理", "物理_化学_通技", 
                                             "物理_生物_政治", "物理_生物_历史", "物理_生物_地理", "物理_生物_通技", "物理_政治_历史", 
                                             "物理_政治_地理", "物理_政治_通技", "物理_历史_地理", "物理_历史_通技", "物理_地理_通技",
                                             "化学_生物_政治", "化学_生物_历史", "化学_生物_地理", "化学_生物_通技", "化学_政治_历史", 
                                             "化学_政治_地理", "化学_政治_通技", "化学_历史_地理", "化学_历史_通技", "化学_地理_通技",
                                             "生物_政治_历史", "生物_政治_地理", "生物_政治_通技", "生物_历史_地理", "生物_历史_通技",
                                             "生物_地理_通技", "政治_历史_地理", "政治_历史_通技", "政治_地理_通技", "历史_地理_通技",
                                             "物理_化学", "物理_生物", "物理_政治", "物理_历史", "物理_地理", "物理_通技", "化学_生物", 
                                             "化学_政治", "化学_历史", "化学_地理", "化学_通技", "生物_政治", "生物_历史", "生物_地理", 
                                             "生物_通技", "政治_历史", "政治_地理", "政治_通技", "历史_地理", "历史_通技", "地理_通技" 
                                          };

        public static string[] TypeName2 = { "物理_化学", "物理_生物", "物理_政治", "物理_历史", "物理_地理", "物理_通技", "化学_生物", 
                                             "化学_政治", "化学_历史", "化学_地理", "化学_通技", "生物_政治", "生物_历史", "生物_地理", 
                                             "生物_通技", "政治_历史", "政治_地理", "政治_通技", "历史_地理", "历史_通技", "地理_通技" 
                                           };

        public static string[] TypeName3 = { "语文", "数学", "英语", "物理", "化学", "生物", "政治", "历史", "地理", "通技" };
        public static List<string> li = Student.TypeName3.ToList<string>();
        public string[] classArr = new string[10];//"chinese","math","english", "ph", "ch", "bi", "po", "hi", "ge", "co" 

        public static int[] Type = new int[36];
        public string Name { get; set; }  // 姓名
        public string Id { get; set; }//学号
        public string Sex { get; set; }//性别
        public string PreClass { get; set; } //班级
        public string Chinese { get; set; }//语文
        public string Math { get; set; }//数学
        public string English { get; set; }//英语
        public string Physics { get; set; }//物理
        public string Chemistry { get; set; }//化学
        public string Biology { get; set; }//生物
        public string Politics { get; set; }//政治
        public string History { get; set; }//历史
        public string Geography { get; set; }//地理
        public string Computer { get; set; }//通技
        public float ChineseScore { get; set; } //语文分数
        public float MathScore { get; set; }//数学分数
        public float EnglishScore { get; set; }//英语分数
        public float PhysicsScore { get; set; }//物理分数
        public float ChemistryScore { get; set; }//化学分数
        public float BiologyScore { get; set; }//生物分数
        public float PoliticsScore { get; set; }//政治分数
        public float HistoryScore { get; set; }//历史分数
        public float GeographyScore { get; set; }//地理分数
        public float ComputerScore { get; set; }//通技分数
        public float TotalScore { get; set; }//总分
        public float ChooseScore { get; set; }//选3 总分
        public int num { get; set; }//名次

        public int GroupId { get; set; }//
        public int type { get; set; }//

        public bool haveClass = false;
        public string ChineseClass { get; set; }
        public string MathClass { get; set; }
        public string EnglishClass { get; set; }
        public string PhysicsClass { get; set; }
        public string ChemistryClass { get; set; }
        public string BiologyClass { get; set; }
        public string PoliticsClass { get; set; }
        public string HistoryClass { get; set; }
        public string GeographyClass { get; set; }
        public string ComputerClass { get; set; }
        public string ChineseName = "语文";
        public string MathName = "数学";
        public string EnglishName = "英语";
        public string PhysicsName = "物理";
        public string ChemistryName = "化学";
        public string BiologyName = "生物";
        public string PoliticsName = "政治";
        public string HistoryName = "历史";
        public string GeographyName = "地理";
        public string ComputerName = "通技";

    }

    class proc3 
    {
        public Dictionary<int, List<string>> typetoStudentIdList = new Dictionary<int, List<string>>();
        public List<Student> Students = new List<Student>();
        public Dictionary<string, Student> StudentsDictionary = new Dictionary<string, Student>();
        public List<Classes> classes = new List<Classes>();
        public List<EachClassWithStudents> EachClassWithStudentsList = new List<EachClassWithStudents>();

        public void ReadAllClass(string path, int index, string learnOrChoose,String classIndex)
        {
            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                    IWorkbook book = new HSSFWorkbook(fs);
                    ISheet sheet = book.GetSheetAt(index);
                    int rFirst = sheet.FirstRowNum;
                    int rLast = sheet.LastRowNum;

                    for (int i = rFirst + 1; i < rLast + 1; i++)
                    {
                        IRow ir = sheet.GetRow(i);
                        Student student = new Student
                        {
                            //Id = ir.GetCell(0).ToString(),
                            //Name = ir.GetCell(1).ToString(),
                            //Physics = ir.GetCell(2).ToString(),
                            //Chemistry = ir.GetCell(3).ToString(),
                            //Biology = ir.GetCell(4).ToString(),
                            //Politics = ir.GetCell(5).ToString(),
                            //History = ir.GetCell(6).ToString(),
                            //Geography = ir.GetCell(7).ToString(),
                            //Computer = ir.GetCell(8).ToString()

                            Id = ir.GetCell(0).ToString(),
                            Name = ir.GetCell(1).ToString(),
                            Sex = ir.GetCell(2).ToString(),
                            PreClass = ir.GetCell(3).ToString(),
                            Chinese = ir.GetCell(4).ToString(),
                            Math = ir.GetCell(5).ToString(),
                            English = ir.GetCell(6).ToString(),
                            Politics = ir.GetCell(7).ToString(),
                            History = ir.GetCell(8).ToString(),
                            Geography = ir.GetCell(9).ToString(),
                            Physics = ir.GetCell(10).ToString(),
                            Chemistry = ir.GetCell(11).ToString(),
                            Biology = ir.GetCell(12).ToString(),
                            Computer = ir.GetCell(13).ToString(),
                            ChineseScore = float.Parse(ir.GetCell(14).ToString()),
                            MathScore = float.Parse(ir.GetCell(15).ToString()),
                            EnglishScore = float.Parse(ir.GetCell(16).ToString()),
                            ChooseScore = float.Parse(ir.GetCell(17).ToString()),
                            TotalScore = float.Parse(ir.GetCell(18).ToString()),
                            num = int.Parse(ir.GetCell(19).ToString()),
                            PoliticsScore = float.Parse(ir.GetCell(20).ToString()),
                            HistoryScore = float.Parse(ir.GetCell(21).ToString()),
                            GeographyScore = float.Parse(ir.GetCell(22).ToString()),
                            PhysicsScore = float.Parse(ir.GetCell(23).ToString()),
                            ChemistryScore = float.Parse(ir.GetCell(24).ToString()),
                            BiologyScore = float.Parse(ir.GetCell(25).ToString()),
                            ComputerScore = float.Parse(ir.GetCell(26).ToString())
                        };

                        student.classArr[3] = student.Physics;
                        student.classArr[4] = student.Chemistry;
                        student.classArr[5] = student.Biology;
                        student.classArr[6] = student.Politics;
                        student.classArr[7] = student.History;
                        student.classArr[8] = student.Geography;
                        student.classArr[9] = student.Computer;

                        int ind = Student.li.IndexOf(classIndex);
                        if(ind <0) continue;
                        if (!student.classArr[ind].Equals(learnOrChoose)) continue;

                        
                        if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.Biology.Equals("选"))
                        {
                            Student.Type[0]++;
                            student.type = 0;
                            if (!typetoStudentIdList.ContainsKey(0))
                            {
                                typetoStudentIdList.Add(0, new List<string>());
                            }
                            typetoStudentIdList[0].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.Politics.Equals("选"))
                        {
                            Student.Type[1]++;
                            student.type = 1;
                            if (!typetoStudentIdList.ContainsKey(1))
                            {
                                typetoStudentIdList.Add(1, new List<string>());
                            }
                            typetoStudentIdList[1].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[2]++;
                            student.type = 2;
                            if (!typetoStudentIdList.ContainsKey(2))
                            {
                                typetoStudentIdList.Add(2, new List<string>());
                            }
                            typetoStudentIdList[2].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[3]++;
                            student.type = 3;
                            if (!typetoStudentIdList.ContainsKey(3))
                            {
                                typetoStudentIdList.Add(3, new List<string>());
                            }
                            typetoStudentIdList[3].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[4]++;
                            student.type = 4;
                            if (!typetoStudentIdList.ContainsKey(4))
                            {
                                typetoStudentIdList.Add(4, new List<string>());
                            }
                            typetoStudentIdList[4].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Biology.Equals("选") && student.Politics.Equals("选"))
                        {
                            Student.Type[5]++;
                            student.type = 5;
                            if (!typetoStudentIdList.ContainsKey(5))
                            {
                                typetoStudentIdList.Add(5, new List<string>());
                            }
                            typetoStudentIdList[5].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Biology.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[6]++;
                            student.type = 6;
                            if (!typetoStudentIdList.ContainsKey(6))
                            {
                                typetoStudentIdList.Add(6, new List<string>());
                            }
                            typetoStudentIdList[6].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Biology.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[7]++;
                            student.type = 7;
                            if (!typetoStudentIdList.ContainsKey(7))
                            {
                                typetoStudentIdList.Add(7, new List<string>());
                            }
                            typetoStudentIdList[7].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Biology.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[8]++;
                            student.type = 8;
                            if (!typetoStudentIdList.ContainsKey(8))
                            {
                                typetoStudentIdList.Add(8, new List<string>());
                            }
                            typetoStudentIdList[8].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Politics.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[9]++;
                            student.type = 9;
                            if (!typetoStudentIdList.ContainsKey(9))
                            {
                                typetoStudentIdList.Add(9, new List<string>());
                            }
                            typetoStudentIdList[9].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Politics.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[10]++;
                            student.type = 10;
                            if (!typetoStudentIdList.ContainsKey(10))
                            {
                                typetoStudentIdList.Add(10, new List<string>());
                            }
                            typetoStudentIdList[10].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Politics.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[11]++;
                            student.type = 11;
                            if (!typetoStudentIdList.ContainsKey(11))
                            {
                                typetoStudentIdList.Add(11, new List<string>());
                            }
                            typetoStudentIdList[11].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.History.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[12]++;
                            student.type = 12;
                            if (!typetoStudentIdList.ContainsKey(12))
                            {
                                typetoStudentIdList.Add(12, new List<string>());
                            }
                            typetoStudentIdList[12].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.History.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[13]++;
                            student.type = 13;
                            if (!typetoStudentIdList.ContainsKey(13))
                            {
                                typetoStudentIdList.Add(13, new List<string>());
                            }
                            typetoStudentIdList[13].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[14]++;
                            student.type = 14;
                            if (!typetoStudentIdList.ContainsKey(14))
                            {
                                typetoStudentIdList.Add(14, new List<string>());
                            }
                            typetoStudentIdList[14].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Biology.Equals("选") && student.Politics.Equals("选"))
                        {
                            Student.Type[15]++;
                            student.type = 15;
                            if (!typetoStudentIdList.ContainsKey(15))
                            {
                                typetoStudentIdList.Add(15, new List<string>());
                            }
                            typetoStudentIdList[15].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Biology.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[16]++;
                            student.type = 16;
                            if (!typetoStudentIdList.ContainsKey(16))
                            {
                                typetoStudentIdList.Add(16, new List<string>());
                            }
                            typetoStudentIdList[16].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Biology.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[17]++;
                            student.type = 17;
                            if (!typetoStudentIdList.ContainsKey(17))
                            {
                                typetoStudentIdList.Add(17, new List<string>());
                            }
                            typetoStudentIdList[17].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Biology.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[18]++;
                            student.type = 18;
                            if (!typetoStudentIdList.ContainsKey(18))
                            {
                                typetoStudentIdList.Add(18, new List<string>());
                            }
                            typetoStudentIdList[18].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Politics.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[19]++;
                            student.type = 19;
                            if (!typetoStudentIdList.ContainsKey(19))
                            {
                                typetoStudentIdList.Add(19, new List<string>());
                            }
                            typetoStudentIdList[19].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Politics.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[20]++;
                            student.type = 20;
                            if (!typetoStudentIdList.ContainsKey(20))
                            {
                                typetoStudentIdList.Add(20, new List<string>());
                            }
                            typetoStudentIdList[20].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Politics.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[21]++;
                            student.type = 21;
                            if (!typetoStudentIdList.ContainsKey(21))
                            {
                                typetoStudentIdList.Add(21, new List<string>());
                            }
                            typetoStudentIdList[21].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.History.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[22]++;
                            student.type = 22;
                            if (!typetoStudentIdList.ContainsKey(22))
                            {
                                typetoStudentIdList.Add(22, new List<string>());
                            }
                            typetoStudentIdList[22].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.History.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[23]++;
                            student.type = 23;
                            if (!typetoStudentIdList.ContainsKey(23))
                            {
                                typetoStudentIdList.Add(23, new List<string>());
                            }
                            typetoStudentIdList[23].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[24]++;
                            student.type = 24;
                            if (!typetoStudentIdList.ContainsKey(24))
                            {
                                typetoStudentIdList.Add(24, new List<string>());
                            }
                            typetoStudentIdList[24].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Politics.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[25]++;
                            student.type = 25;
                            if (!typetoStudentIdList.ContainsKey(25))
                            {
                                typetoStudentIdList.Add(25, new List<string>());
                            }
                            typetoStudentIdList[25].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Politics.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[26]++;
                            student.type = 26;
                            if (!typetoStudentIdList.ContainsKey(26))
                            {
                                typetoStudentIdList.Add(26, new List<string>());
                            }
                            typetoStudentIdList[26].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Politics.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[27]++;
                            student.type = 27;
                            if (!typetoStudentIdList.ContainsKey(27))
                            {
                                typetoStudentIdList.Add(27, new List<string>());
                            }
                            typetoStudentIdList[27].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.History.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[28]++;
                            student.type = 28;
                            if (!typetoStudentIdList.ContainsKey(28))
                            {
                                typetoStudentIdList.Add(28, new List<string>());
                            }
                            typetoStudentIdList[28].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.History.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[29]++;
                            student.type = 29;
                            if (!typetoStudentIdList.ContainsKey(29))
                            {
                                typetoStudentIdList.Add(29, new List<string>());
                            }
                            typetoStudentIdList[29].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[30]++;
                            student.type = 30;
                            if (!typetoStudentIdList.ContainsKey(30))
                            {
                                typetoStudentIdList.Add(30, new List<string>());
                            }
                            typetoStudentIdList[30].Add(student.Id);
                        }
                        else if (student.Politics.Equals("选") && student.History.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[31]++;
                            student.type = 31;
                            if (!typetoStudentIdList.ContainsKey(31))
                            {
                                typetoStudentIdList.Add(31, new List<string>());
                            }
                            typetoStudentIdList[31].Add(student.Id);
                        }
                        else if (student.Politics.Equals("选") && student.History.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[32]++;
                            student.type = 32;
                            if (!typetoStudentIdList.ContainsKey(32))
                            {
                                typetoStudentIdList.Add(32, new List<string>());
                            }
                            typetoStudentIdList[32].Add(student.Id);
                        }
                        else if (student.Politics.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[33]++;
                            student.type = 33;
                            if (!typetoStudentIdList.ContainsKey(33))
                            {
                                typetoStudentIdList.Add(33, new List<string>());
                            }
                            typetoStudentIdList[33].Add(student.Id);
                        }
                        else if (student.History.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[34]++;
                            student.type = 34;
                            if (!typetoStudentIdList.ContainsKey(34))
                            {
                                typetoStudentIdList.Add(34, new List<string>());
                            }
                            typetoStudentIdList[34].Add(student.Id);
                        }

                        

                        Students.Add(student);

                        StudentsDictionary.Add(student.Id, student);
                        ir = null;
                    }
                    sheet = null;
                    book = null;


                }
            }
            catch (Exception e)
            {
                Console.WriteLine("ReadAllClass:" + e.Message);
            }

        }

        public void WriteAllStudentsAndTypes(string filename)
        {
            try
            {
                HSSFWorkbook book = new HSSFWorkbook();
                ISheet sheet = book.CreateSheet("学生名单");
                IRow row0 = sheet.CreateRow(0);
                row0.CreateCell(0).SetCellValue("学号");
                row0.CreateCell(1).SetCellValue("姓名");
                row0.CreateCell(2).SetCellValue("性别");
                row0.CreateCell(3).SetCellValue("班级");
                row0.CreateCell(4).SetCellValue("语文");
                row0.CreateCell(5).SetCellValue("数学");
                row0.CreateCell(6).SetCellValue("英语");
                row0.CreateCell(7).SetCellValue("政治");
                row0.CreateCell(8).SetCellValue("历史");
                row0.CreateCell(9).SetCellValue("地理");
                row0.CreateCell(10).SetCellValue("物理");
                row0.CreateCell(11).SetCellValue("化学");
                row0.CreateCell(12).SetCellValue("生物");
                row0.CreateCell(13).SetCellValue("通技");
                row0.CreateCell(14).SetCellValue("语文150");
                row0.CreateCell(15).SetCellValue("数学150");
                row0.CreateCell(16).SetCellValue("英语150");
                row0.CreateCell(17).SetCellValue("选课300");
                row0.CreateCell(18).SetCellValue("总分750");
                row0.CreateCell(19).SetCellValue("名次");
                row0.CreateCell(20).SetCellValue("政治赋分");
                row0.CreateCell(21).SetCellValue("历史赋分");
                row0.CreateCell(22).SetCellValue("地理赋分");
                row0.CreateCell(23).SetCellValue("物理赋分");
                row0.CreateCell(24).SetCellValue("化学赋分");
                row0.CreateCell(25).SetCellValue("生物赋分");
                row0.CreateCell(26).SetCellValue("通技赋分");
                int id = 1;
                
                foreach(Student s in Students)
                {
                    IRow row = sheet.CreateRow(id++);

                    row.CreateCell(0).SetCellValue(s.Id);
                    row.CreateCell(1).SetCellValue(s.Name);
                    row.CreateCell(2).SetCellValue(s.Sex);
                    row.CreateCell(3).SetCellValue(s.PreClass);
                    row.CreateCell(4).SetCellValue(s.Chinese);
                    row.CreateCell(5).SetCellValue(s.Math);
                    row.CreateCell(6).SetCellValue(s.English);
                    row.CreateCell(7).SetCellValue(s.Politics);
                    row.CreateCell(8).SetCellValue(s.History);
                    row.CreateCell(9).SetCellValue(s.Geography);
                    row.CreateCell(10).SetCellValue(s.Physics);
                    row.CreateCell(11).SetCellValue(s.Chemistry);
                    row.CreateCell(12).SetCellValue(s.Biology);
                    row.CreateCell(13).SetCellValue(s.Computer);
                    row.CreateCell(14).SetCellValue(s.ChineseScore);
                    row.CreateCell(15).SetCellValue(s.MathScore);
                    row.CreateCell(16).SetCellValue(s.EnglishScore);
                    row.CreateCell(17).SetCellValue(s.ChooseScore);
                    row.CreateCell(18).SetCellValue(s.TotalScore);
                    row.CreateCell(19).SetCellValue(s.num);
                    row.CreateCell(20).SetCellValue(s.PoliticsScore);
                    row.CreateCell(21).SetCellValue(s.HistoryScore);
                    row.CreateCell(22).SetCellValue(s.GeographyScore);
                    row.CreateCell(23).SetCellValue(s.PhysicsScore);
                    row.CreateCell(24).SetCellValue(s.ChemistryScore);
                    row.CreateCell(25).SetCellValue(s.BiologyScore);
                    row.CreateCell(26).SetCellValue(s.ComputerScore);
                 }

                sheet = book.CreateSheet("Types");
                row0 = sheet.CreateRow(0);
                row0.CreateCell(0).SetCellValue("类编号");
                row0.CreateCell(1).SetCellValue("类名");
                row0.CreateCell(2).SetCellValue("人数");
                id = 1;
                for (int i = 0; i < 35; i++)
                {
                    if (Student.Type[i] != 0)
                    {
                        IRow row = sheet.CreateRow(id++);
                        row.CreateCell(0).SetCellValue(i);
                        row.CreateCell(1).SetCellValue(Student.TypeName[i]);
                        row.CreateCell(2).SetCellValue(Student.Type[i]);
                    }
                }

                //写到客户端
                FileStream file = new FileStream(filename, FileMode.OpenOrCreate);
                book.Write(file);
                file.Flush();
                file.Close();

            }
            catch (Exception e)
            {
                Console.WriteLine("WriteAll " + e.Message);
            }
            return;
        }

        public void PrintClasses(string path)
        {
            try
            {
                HSSFWorkbook book = new HSSFWorkbook();
                int idd = 1;
                foreach (Classes c in classes)
                {
                    ISheet sheet = book.CreateSheet("class_"+idd+"学生名单");
                    IRow row0 = sheet.CreateRow(0);
                    row0.CreateCell(0).SetCellValue("学号");
                    row0.CreateCell(1).SetCellValue("姓名");
                    row0.CreateCell(2).SetCellValue("性别");
                    row0.CreateCell(3).SetCellValue("班级");
                    row0.CreateCell(4).SetCellValue("语文");
                    row0.CreateCell(5).SetCellValue("数学");
                    row0.CreateCell(6).SetCellValue("英语");
                    row0.CreateCell(7).SetCellValue("政治");
                    row0.CreateCell(8).SetCellValue("历史");
                    row0.CreateCell(9).SetCellValue("地理");
                    row0.CreateCell(10).SetCellValue("物理");
                    row0.CreateCell(11).SetCellValue("化学");
                    row0.CreateCell(12).SetCellValue("生物");
                    row0.CreateCell(13).SetCellValue("通技");
                    row0.CreateCell(14).SetCellValue("语文150");
                    row0.CreateCell(15).SetCellValue("数学150");
                    row0.CreateCell(16).SetCellValue("英语150");
                    row0.CreateCell(17).SetCellValue("选课300");
                    row0.CreateCell(18).SetCellValue("总分750");
                    row0.CreateCell(19).SetCellValue("名次");
                    row0.CreateCell(20).SetCellValue("政治赋分");
                    row0.CreateCell(21).SetCellValue("历史赋分");
                    row0.CreateCell(22).SetCellValue("地理赋分");
                    row0.CreateCell(23).SetCellValue("物理赋分");
                    row0.CreateCell(24).SetCellValue("化学赋分");
                    row0.CreateCell(25).SetCellValue("生物赋分");
                    row0.CreateCell(26).SetCellValue("通技赋分");
                    int id = 1;

                    foreach (Student s in c.students)
                    {
                        IRow row = sheet.CreateRow(id++);

                        row.CreateCell(0).SetCellValue(s.Id);
                        row.CreateCell(1).SetCellValue(s.Name);
                        row.CreateCell(2).SetCellValue(s.Sex);
                        row.CreateCell(3).SetCellValue(s.PreClass);
                        row.CreateCell(4).SetCellValue(s.Chinese);
                        row.CreateCell(5).SetCellValue(s.Math);
                        row.CreateCell(6).SetCellValue(s.English);
                        row.CreateCell(7).SetCellValue(s.Politics);
                        row.CreateCell(8).SetCellValue(s.History);
                        row.CreateCell(9).SetCellValue(s.Geography);
                        row.CreateCell(10).SetCellValue(s.Physics);
                        row.CreateCell(11).SetCellValue(s.Chemistry);
                        row.CreateCell(12).SetCellValue(s.Biology);
                        row.CreateCell(13).SetCellValue(s.Computer);
                        row.CreateCell(14).SetCellValue(s.ChineseScore);
                        row.CreateCell(15).SetCellValue(s.MathScore);
                        row.CreateCell(16).SetCellValue(s.EnglishScore);
                        row.CreateCell(17).SetCellValue(s.ChooseScore);
                        row.CreateCell(18).SetCellValue(s.TotalScore);
                        row.CreateCell(19).SetCellValue(s.num);
                        row.CreateCell(20).SetCellValue(s.PoliticsScore);
                        row.CreateCell(21).SetCellValue(s.HistoryScore);
                        row.CreateCell(22).SetCellValue(s.GeographyScore);
                        row.CreateCell(23).SetCellValue(s.PhysicsScore);
                        row.CreateCell(24).SetCellValue(s.ChemistryScore);
                        row.CreateCell(25).SetCellValue(s.BiologyScore);
                        row.CreateCell(26).SetCellValue(s.ComputerScore);
                    }

                    sheet = book.CreateSheet("class_"+idd+"Types");
                    idd++;
                    row0 = sheet.CreateRow(0);
                    row0.CreateCell(0).SetCellValue("类编号");
                    row0.CreateCell(1).SetCellValue("类名");
                    row0.CreateCell(2).SetCellValue("人数");
                    id = 1;
                    int[] types = new int[35];
                    for (int i = 0; i < 35; i++)
                        types[i] = 0;
                    foreach (Student s in c.students)
                    {
                        types[s.type]++;
                    }

                    for (int i = 0; i < 35; i++)
                    {
                        if (types[i] != 0)
                        {
                            IRow row = sheet.CreateRow(id++);
                            row.CreateCell(0).SetCellValue(i);
                            row.CreateCell(1).SetCellValue(Student.TypeName[i]);
                            row.CreateCell(2).SetCellValue(Student.Type[i]);
                        }
                    }

                    //写到客户端
                    FileStream file = new FileStream(path, FileMode.OpenOrCreate);
                    book.Write(file);
                    file.Flush();
                    file.Close();

                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        public void method0(List<int> aa, List<int> groupnum, int classnum)
        {
            List<xiaoleiherenshu> union = new List<xiaoleiherenshu>();
            foreach (int i in aa)
            {
                xiaoleiherenshu x = new xiaoleiherenshu();
                x.xiaolei = i;
                x.renshu = Student.Type[i];
                x.flag = false;
                union.Add(x);
            }
            union.Sort((left, right) =>
            {
                if (left.renshu > right.renshu)
                    return -1;
                else if (left.renshu < right.renshu)
                    return 1;
                else return 0;
            });

            groupnum.Reverse();


            int last = union.Count - 1;
            foreach (int num in groupnum)
            {
                int sum = 0;
                foreach (List<string> li in typetoStudentIdList.Values)
                {
                    sum += li.Count;
                }

                int ss = 0;
                foreach (xiaoleiherenshu xxx in union)
                {
                    ss += xxx.renshu;
                }
                Classes newcls = new Classes();
                Boolean flag = false;
                int peoplenum = num;

                for (int i = 0; i < union.Count; i++)
                {
                    if (i > last)
                    {
                        break;
                    }
                    if (union[i].flag == true && i < last) continue;
                    if (union[i].flag == true && i == last && peoplenum != 0)
                    {
                        i = -1;
                        continue;
                    }
                    if (union[i].renshu <= peoplenum)
                    {
                        flag = true;
                        while (typetoStudentIdList[union[i].xiaolei].Count != 0)
                        {
                            newcls.students.Add(StudentsDictionary[typetoStudentIdList[union[i].xiaolei].First<string>()]);
                            typetoStudentIdList[union[i].xiaolei].Remove(typetoStudentIdList[union[i].xiaolei].First<string>());
                        }
                        peoplenum -= union[i].renshu;
                        union[i].renshu = 0;
                        union[i].flag = true;
                        if (i == last)
                        {
                            for (int j = union.Count - 1; j >= 0; j--)
                            {
                                if (union[j].flag == false)
                                {
                                    last = j;
                                    break;
                                }
                            }
                        }
                        if (peoplenum == 0) break;
                    }
                    else
                    {
                        if (flag == false || i == last)  //拆 (超人数上限 或 是最后小类)
                        {
                            while (peoplenum != 0)
                            {
                                newcls.students.Add(StudentsDictionary[typetoStudentIdList[union[i].xiaolei].First<string>()]);
                                typetoStudentIdList[union[i].xiaolei].Remove(typetoStudentIdList[union[i].xiaolei].First<string>());
                                peoplenum--;
                                union[i].renshu--;
                                if (union[i].renshu == 0)
                                {
                                    union[i].flag = true;
                                    break;
                                }
                            }
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    if (i == last && peoplenum != 0)
                        i = -1;
                }
                classes.Add(newcls);
            }
            return;
        }

        public void ReadClassDetail(string path,string subpath)
        {
            StreamReader sr = new StreamReader(subpath+path);
            String line;
            while ((line = sr.ReadLine()) != null)
            {
                Console.WriteLine(line.ToString());
                if (line.Length <= 3) continue;
                string learnOrChoose = null;
                if (line.Contains("选"))
                    learnOrChoose = "选";
                else
                    learnOrChoose = "学";

                for (int xx = 0; xx < 35; xx++)
                    Student.Type[xx] = 0;

                Students.Clear();
                StudentsDictionary.Clear();
                classes.Clear();

                for (int i = 1; i < 10; i++)
                {
                    if (line.Contains("" + i))
                    {
                        ReadAllClass(subpath + "AllClass.xls", i - 1, learnOrChoose, line.Substring(0, 2));
                    }
                }
                Console.WriteLine(Students.Count);
                WriteAllStudentsAndTypes(subpath + line.Substring(0, 3) + ".xls");
                int allsum = Students.Count;
                int num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                List<int> groupnumList = new List<int>();
                int n = num;
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                List<int> newli = new List<int>();

                for (int i = 0; i < 35; i++)
                {
                    if (Student.Type[i] != 0)
                        newli.Add(i);
                }

                method0(newli, groupnumList, n);

                PrintClasses( subpath + line.Substring(0, 3) + "详细分班.xls");
            }
        }
        public void ReadGroupClass(string path)
        {
            try
            {
                using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                    IWorkbook book = new HSSFWorkbook(fs);
                    ISheet sheet = book.GetSheetAt(1);
                    int rFirst = sheet.FirstRowNum;
                    int rLast = sheet.LastRowNum;

                    for (int i = rFirst + 1; i < rLast + 1; i++)
                    {
                        IRow ir = sheet.GetRow(i);
                        string str = null;
                        Student student = new Student();

                        student.GroupId = int.Parse(ir.GetCell(0).ToString());
                        student.Id =ir.GetCell(1).ToString();
                        student.Name = ir.GetCell(2).ToString();
                        student.Sex = ir.GetCell(3).ToString();
                        student.ChineseClass = ir.GetCell(4).ToString().Substring(2);
                        student.MathClass = ir.GetCell(5).ToString().Substring(2);
                        student.EnglishClass = ir.GetCell(6).ToString().Substring(2);

                        str = ir.GetCell(7).ToString();
                        student.PhysicsClass = str.Substring(str.Length-2);
                        student.PhysicsName = str.Substring(0,str.Length-2);
                        student.Physics = str.Contains("选") ? "选" : "学";
                        str = ir.GetCell(8).ToString();
                        student.ChemistryClass = str.Substring(str.Length - 2);
                        student.ChemistryName = str.Substring(0, str.Length - 2); 
                        student.Chemistry = str.Contains("选") ? "选" : "学";
                        str = ir.GetCell(9).ToString();
                        student.BiologyClass = str.Substring(str.Length - 2);
                        student.BiologyName = str.Substring(0, str.Length - 2); 
                        student.Biology = str.Contains("选") ? "选" : "学";
                        str = ir.GetCell(10).ToString();
                        student.PoliticsClass = str.Substring(str.Length - 2);
                        student.PoliticsName = str.Substring(0, str.Length - 2); 
                        student.Politics = str.Contains("选") ? "选" : "学";
                        str = ir.GetCell(11).ToString();
                        student.HistoryClass = str.Substring(str.Length - 2);
                        student.HistoryName = str.Substring(0, str.Length - 2);
                        student.History = str.Contains("选") ? "选" : "学";
                        str = ir.GetCell(12).ToString();
                        student.GeographyClass = str.Substring(str.Length - 2);
                        student.GeographyName = str.Substring(0, str.Length - 2);
                        student.Geography = str.Contains("选") ? "选" : "学";
                        str = ir.GetCell(13).ToString();
                        student.ComputerClass = str.Substring(str.Length - 2);
                        student.ComputerName = str.Substring(0, str.Length - 2);
                        student.Computer = str.Contains("选") ? "选" : "学";

                        student.ChineseScore = float.Parse(ir.GetCell(14).ToString());
                        student.MathScore = float.Parse(ir.GetCell(15).ToString());
                        student.EnglishScore = float.Parse(ir.GetCell(16).ToString());
                        student.ChooseScore = float.Parse(ir.GetCell(17).ToString());
                        student.TotalScore = float.Parse(ir.GetCell(18).ToString());
                        student.num = int.Parse(ir.GetCell(19).ToString());

                        student.PoliticsScore = float.Parse(ir.GetCell(20).ToString());
                        student.HistoryScore = float.Parse(ir.GetCell(21).ToString());
                        student.GeographyScore = float.Parse(ir.GetCell(22).ToString());
                        student.PhysicsScore = float.Parse(ir.GetCell(23).ToString());
                        student.ChemistryScore = float.Parse(ir.GetCell(24).ToString());
                        student.BiologyScore = float.Parse(ir.GetCell(25).ToString());
                        student.ComputerScore = float.Parse(ir.GetCell(26).ToString());

                        if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.Biology.Equals("选"))
                        {
                            Student.Type[0]++;
                            student.type = 0;
                            if (!typetoStudentIdList.ContainsKey(0))
                            {
                                typetoStudentIdList.Add(0, new List<string>());
                            }
                            typetoStudentIdList[0].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.Politics.Equals("选"))
                        {
                            Student.Type[1]++;
                            student.type = 1;
                            if (!typetoStudentIdList.ContainsKey(1))
                            {
                                typetoStudentIdList.Add(1, new List<string>());
                            }
                            typetoStudentIdList[1].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[2]++;
                            student.type = 2;
                            if (!typetoStudentIdList.ContainsKey(2))
                            {
                                typetoStudentIdList.Add(2, new List<string>());
                            }
                            typetoStudentIdList[2].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[3]++;
                            student.type = 3;
                            if (!typetoStudentIdList.ContainsKey(3))
                            {
                                typetoStudentIdList.Add(3, new List<string>());
                            }
                            typetoStudentIdList[3].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Chemistry.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[4]++;
                            student.type = 4;
                            if (!typetoStudentIdList.ContainsKey(4))
                            {
                                typetoStudentIdList.Add(4, new List<string>());
                            }
                            typetoStudentIdList[4].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Biology.Equals("选") && student.Politics.Equals("选"))
                        {
                            Student.Type[5]++;
                            student.type = 5;
                            if (!typetoStudentIdList.ContainsKey(5))
                            {
                                typetoStudentIdList.Add(5, new List<string>());
                            }
                            typetoStudentIdList[5].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Biology.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[6]++;
                            student.type = 6;
                            if (!typetoStudentIdList.ContainsKey(6))
                            {
                                typetoStudentIdList.Add(6, new List<string>());
                            }
                            typetoStudentIdList[6].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Biology.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[7]++;
                            student.type = 7;
                            if (!typetoStudentIdList.ContainsKey(7))
                            {
                                typetoStudentIdList.Add(7, new List<string>());
                            }
                            typetoStudentIdList[7].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Biology.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[8]++;
                            student.type = 8;
                            if (!typetoStudentIdList.ContainsKey(8))
                            {
                                typetoStudentIdList.Add(8, new List<string>());
                            }
                            typetoStudentIdList[8].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Politics.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[9]++;
                            student.type = 9;
                            if (!typetoStudentIdList.ContainsKey(9))
                            {
                                typetoStudentIdList.Add(9, new List<string>());
                            }
                            typetoStudentIdList[9].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Politics.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[10]++;
                            student.type = 10;
                            if (!typetoStudentIdList.ContainsKey(10))
                            {
                                typetoStudentIdList.Add(10, new List<string>());
                            }
                            typetoStudentIdList[10].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Politics.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[11]++;
                            student.type = 11;
                            if (!typetoStudentIdList.ContainsKey(11))
                            {
                                typetoStudentIdList.Add(11, new List<string>());
                            }
                            typetoStudentIdList[11].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.History.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[12]++;
                            student.type = 12;
                            if (!typetoStudentIdList.ContainsKey(12))
                            {
                                typetoStudentIdList.Add(12, new List<string>());
                            }
                            typetoStudentIdList[12].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.History.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[13]++;
                            student.type = 13;
                            if (!typetoStudentIdList.ContainsKey(13))
                            {
                                typetoStudentIdList.Add(13, new List<string>());
                            }
                            typetoStudentIdList[13].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[14]++;
                            student.type = 14;
                            if (!typetoStudentIdList.ContainsKey(14))
                            {
                                typetoStudentIdList.Add(14, new List<string>());
                            }
                            typetoStudentIdList[14].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Biology.Equals("选") && student.Politics.Equals("选"))
                        {
                            Student.Type[15]++;
                            student.type = 15;
                            if (!typetoStudentIdList.ContainsKey(15))
                            {
                                typetoStudentIdList.Add(15, new List<string>());
                            }
                            typetoStudentIdList[15].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Biology.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[16]++;
                            student.type = 16;
                            if (!typetoStudentIdList.ContainsKey(16))
                            {
                                typetoStudentIdList.Add(16, new List<string>());
                            }
                            typetoStudentIdList[16].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Biology.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[17]++;
                            student.type = 17;
                            if (!typetoStudentIdList.ContainsKey(17))
                            {
                                typetoStudentIdList.Add(17, new List<string>());
                            }
                            typetoStudentIdList[17].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Biology.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[18]++;
                            student.type = 18;
                            if (!typetoStudentIdList.ContainsKey(18))
                            {
                                typetoStudentIdList.Add(18, new List<string>());
                            }
                            typetoStudentIdList[18].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Politics.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[19]++;
                            student.type = 19;
                            if (!typetoStudentIdList.ContainsKey(19))
                            {
                                typetoStudentIdList.Add(19, new List<string>());
                            }
                            typetoStudentIdList[19].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Politics.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[20]++;
                            student.type = 20;
                            if (!typetoStudentIdList.ContainsKey(20))
                            {
                                typetoStudentIdList.Add(20, new List<string>());
                            }
                            typetoStudentIdList[20].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Politics.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[21]++;
                            student.type = 21;
                            if (!typetoStudentIdList.ContainsKey(21))
                            {
                                typetoStudentIdList.Add(21, new List<string>());
                            }
                            typetoStudentIdList[21].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.History.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[22]++;
                            student.type = 22;
                            if (!typetoStudentIdList.ContainsKey(22))
                            {
                                typetoStudentIdList.Add(22, new List<string>());
                            }
                            typetoStudentIdList[22].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.History.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[23]++;
                            student.type = 23;
                            if (!typetoStudentIdList.ContainsKey(23))
                            {
                                typetoStudentIdList.Add(23, new List<string>());
                            }
                            typetoStudentIdList[23].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[24]++;
                            student.type = 24;
                            if (!typetoStudentIdList.ContainsKey(24))
                            {
                                typetoStudentIdList.Add(24, new List<string>());
                            }
                            typetoStudentIdList[24].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Politics.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[25]++;
                            student.type = 25;
                            if (!typetoStudentIdList.ContainsKey(25))
                            {
                                typetoStudentIdList.Add(25, new List<string>());
                            }
                            typetoStudentIdList[25].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Politics.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[26]++;
                            student.type = 26;
                            if (!typetoStudentIdList.ContainsKey(26))
                            {
                                typetoStudentIdList.Add(26, new List<string>());
                            }
                            typetoStudentIdList[26].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Politics.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[27]++;
                            student.type = 27;
                            if (!typetoStudentIdList.ContainsKey(27))
                            {
                                typetoStudentIdList.Add(27, new List<string>());
                            }
                            typetoStudentIdList[27].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.History.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[28]++;
                            student.type = 28;
                            if (!typetoStudentIdList.ContainsKey(28))
                            {
                                typetoStudentIdList.Add(28, new List<string>());
                            }
                            typetoStudentIdList[28].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.History.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[29]++;
                            student.type = 29;
                            if (!typetoStudentIdList.ContainsKey(29))
                            {
                                typetoStudentIdList.Add(29, new List<string>());
                            }
                            typetoStudentIdList[29].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[30]++;
                            student.type = 30;
                            if (!typetoStudentIdList.ContainsKey(30))
                            {
                                typetoStudentIdList.Add(30, new List<string>());
                            }
                            typetoStudentIdList[30].Add(student.Id);
                        }
                        else if (student.Politics.Equals("选") && student.History.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[31]++;
                            student.type = 31;
                            if (!typetoStudentIdList.ContainsKey(31))
                            {
                                typetoStudentIdList.Add(31, new List<string>());
                            }
                            typetoStudentIdList[31].Add(student.Id);
                        }
                        else if (student.Politics.Equals("选") && student.History.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[32]++;
                            student.type = 32;
                            if (!typetoStudentIdList.ContainsKey(32))
                            {
                                typetoStudentIdList.Add(32, new List<string>());
                            }
                            typetoStudentIdList[32].Add(student.Id);
                        }
                        else if (student.Politics.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[33]++;
                            student.type = 33;
                            if (!typetoStudentIdList.ContainsKey(33))
                            {
                                typetoStudentIdList.Add(33, new List<string>());
                            }
                            typetoStudentIdList[33].Add(student.Id);
                        }
                        else if (student.History.Equals("选") && student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[34]++;
                            student.type = 34;
                            if (!typetoStudentIdList.ContainsKey(34))
                            {
                                typetoStudentIdList.Add(34, new List<string>());
                            }
                            typetoStudentIdList[34].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Chemistry.Equals("选"))
                        {
                            Student.Type[35]++;
                            student.type = 35;
                            if (!typetoStudentIdList.ContainsKey(35))
                            {
                                typetoStudentIdList.Add(35, new List<string>());
                            }
                            typetoStudentIdList[35].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Biology.Equals("选"))
                        {
                            Student.Type[36]++;
                            student.type = 36;
                            if (!typetoStudentIdList.ContainsKey(36))
                            {
                                typetoStudentIdList.Add(36, new List<string>());
                            }
                            typetoStudentIdList[36].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Politics.Equals("选"))
                        {
                            Student.Type[37]++;
                            student.type = 37;
                            if (!typetoStudentIdList.ContainsKey(37))
                            {
                                typetoStudentIdList.Add(37, new List<string>());
                            }
                            typetoStudentIdList[37].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[38]++;
                            student.type = 38;
                            if (!typetoStudentIdList.ContainsKey(38))
                            {
                                typetoStudentIdList.Add(38, new List<string>());
                            }
                            typetoStudentIdList[38].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[39]++;
                            student.type = 39;
                            if (!typetoStudentIdList.ContainsKey(39))
                            {
                                typetoStudentIdList.Add(39, new List<string>());
                            }
                            typetoStudentIdList[39].Add(student.Id);
                        }
                        else if (student.Physics.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[40]++;
                            student.type = 40;
                            if (!typetoStudentIdList.ContainsKey(40))
                            {
                                typetoStudentIdList.Add(40, new List<string>());
                            }
                            typetoStudentIdList[40].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Biology.Equals("选"))
                        {
                            Student.Type[41]++;
                            student.type = 41;
                            if (!typetoStudentIdList.ContainsKey(41))
                            {
                                typetoStudentIdList.Add(41, new List<string>());
                            }
                            typetoStudentIdList[41].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Politics.Equals("选"))
                        {
                            Student.Type[42]++;
                            student.type = 42;
                            if (!typetoStudentIdList.ContainsKey(42))
                            {
                                typetoStudentIdList.Add(42, new List<string>());
                            }
                            typetoStudentIdList[42].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[43]++;
                            student.type = 43;
                            if (!typetoStudentIdList.ContainsKey(43))
                            {
                                typetoStudentIdList.Add(43, new List<string>());
                            }
                            typetoStudentIdList[43].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[44]++;
                            student.type = 44;
                            if (!typetoStudentIdList.ContainsKey(44))
                            {
                                typetoStudentIdList.Add(44, new List<string>());
                            }
                            typetoStudentIdList[44].Add(student.Id);
                        }
                        else if (student.Chemistry.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[45]++;
                            student.type = 45;
                            if (!typetoStudentIdList.ContainsKey(45))
                            {
                                typetoStudentIdList.Add(45, new List<string>());
                            }
                            typetoStudentIdList[45].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Politics.Equals("选"))
                        {
                            Student.Type[46]++;
                            student.type = 46;
                            if (!typetoStudentIdList.ContainsKey(46))
                            {
                                typetoStudentIdList.Add(46, new List<string>());
                            }
                            typetoStudentIdList[46].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[47]++;
                            student.type = 47;
                            if (!typetoStudentIdList.ContainsKey(47))
                            {
                                typetoStudentIdList.Add(47, new List<string>());
                            }
                            typetoStudentIdList[47].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[48]++;
                            student.type = 48;
                            if (!typetoStudentIdList.ContainsKey(48))
                            {
                                typetoStudentIdList.Add(48, new List<string>());
                            }
                            typetoStudentIdList[48].Add(student.Id);
                        }
                        else if (student.Biology.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[49]++;
                            student.type = 49;
                            if (!typetoStudentIdList.ContainsKey(49))
                            {
                                typetoStudentIdList.Add(49, new List<string>());
                            }
                            typetoStudentIdList[49].Add(student.Id);
                        }
                        else if (student.Politics.Equals("选") && student.History.Equals("选"))
                        {
                            Student.Type[50]++;
                            student.type = 50;
                            if (!typetoStudentIdList.ContainsKey(50))
                            {
                                typetoStudentIdList.Add(50, new List<string>());
                            }
                            typetoStudentIdList[50].Add(student.Id);
                        }
                        else if (student.Politics.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[51]++;
                            student.type = 51;
                            if (!typetoStudentIdList.ContainsKey(51))
                            {
                                typetoStudentIdList.Add(51, new List<string>());
                            }
                            typetoStudentIdList[51].Add(student.Id);
                        }
                        else if (student.Politics.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[52]++;
                            student.type = 52;
                            if (!typetoStudentIdList.ContainsKey(52))
                            {
                                typetoStudentIdList.Add(52, new List<string>());
                            }
                            typetoStudentIdList[52].Add(student.Id);
                        }
                        else if (student.History.Equals("选") && student.Geography.Equals("选"))
                        {
                            Student.Type[53]++;
                            student.type = 53;
                            if (!typetoStudentIdList.ContainsKey(53))
                            {
                                typetoStudentIdList.Add(53, new List<string>());
                            }
                            typetoStudentIdList[53].Add(student.Id);
                        }
                        else if (student.History.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[54]++;
                            student.type = 54;
                            if (!typetoStudentIdList.ContainsKey(54))
                            {
                                typetoStudentIdList.Add(54, new List<string>());
                            }
                            typetoStudentIdList[54].Add(student.Id);
                        }
                        else if (student.Geography.Equals("选") && student.Computer.Equals("选"))
                        {
                            Student.Type[55]++;
                            student.type = 55;
                            if (!typetoStudentIdList.ContainsKey(55))
                            {
                                typetoStudentIdList.Add(55, new List<string>());
                            }
                            typetoStudentIdList[55].Add(student.Id);
                        }
                        student.classArr[3] = student.Physics;
                        student.classArr[4] = student.Chemistry;
                        student.classArr[5] = student.Biology;
                        student.classArr[6] = student.Politics;
                        student.classArr[7] = student.History;
                        student.classArr[8] = student.Geography;
                        student.classArr[9] = student.Computer;

                        Students.Add(student);
                        StudentsDictionary.Add(student.Id, student);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

        }

        public void ReallotMixClass()
        {
            List<Student> listStudent = new List<Student>();
            List<int> groupnumList = new List<int>();
            int allsum,num,n;


            //physics
            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Physics.Equals("选") && int.Parse(s.PhysicsClass) > 10 && int.Parse(s.PhysicsClass)<20 )
                {
                    listStudent.Add(s);
                }
            }
            if(listStudent.Count!=0){
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0,j=0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].PhysicsClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Physics.Equals("学") && int.Parse(s.PhysicsClass) > 10 && int.Parse(s.PhysicsClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].PhysicsClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }

            //chemistry
            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Chemistry.Equals("选") && int.Parse(s.ChemistryClass) > 10 && int.Parse(s.ChemistryClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {

                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].ChemistryClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Chemistry.Equals("学") && int.Parse(s.ChemistryClass) > 10 && int.Parse(s.ChemistryClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].ChemistryClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }
            //biology
            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Biology.Equals("选") && int.Parse(s.BiologyClass) > 10 && int.Parse(s.BiologyClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].BiologyClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Biology.Equals("学") && int.Parse(s.BiologyClass) > 10 && int.Parse(s.BiologyClass) < 20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].BiologyClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }
            //politics

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Politics.Equals("选") && int.Parse(s.PoliticsClass) > 10 && int.Parse(s.PoliticsClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].PoliticsClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Politics.Equals("学") && int.Parse(s.PoliticsClass) > 10 && int.Parse(s.PoliticsClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].PoliticsClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }
            //history
            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.History.Equals("选") && int.Parse(s.HistoryClass) > 10 && int.Parse(s.HistoryClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].HistoryClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.History.Equals("学") && int.Parse(s.HistoryClass) > 10 && int.Parse(s.HistoryClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].HistoryClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }
            //geography

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Geography.Equals("选") && int.Parse(s.GeographyClass) > 10 && int.Parse(s.GeographyClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].GeographyClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Geography.Equals("学") && int.Parse(s.GeographyClass) > 10 && int.Parse(s.GeographyClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].GeographyClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }
            //computer

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Computer.Equals("选") && int.Parse(s.ComputerClass) > 10 && int.Parse(s.ComputerClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].ComputerClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }

            listStudent.Clear();
            foreach (Student s in Students)
            {
                if (s.Computer.Equals("学") && int.Parse(s.ComputerClass) > 10 && int.Parse(s.ComputerClass)<20)
                {
                    listStudent.Add(s);
                }
            }
            if (listStudent.Count != 0)
            {
                allsum = listStudent.Count;
                num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                n = num;
                groupnumList.Clear();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < listStudent.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    StudentsDictionary[listStudent[i].Id].ComputerClass = (11 + j).ToString();
                    groupnumList[j]--;
                }
            }
            Console.Write("");

            PrintGroupClass("./IO/Group班级.xls");
        }

        public bool checkStudent(Student a,Student b)
        {
            if(!a.ChineseClass.Equals(b.ChineseClass) )
                return false;
            if (!a.MathClass.Equals(b.MathClass))
                return false;
            if (!a.EnglishClass.Equals(b.EnglishClass))
                return false;
            if (!(a.Physics + a.PhysicsClass).Equals(b.Physics + b.PhysicsClass))
                return false;
            if (!(a.Chemistry + a.ChemistryClass).Equals(b.Chemistry + b.ChemistryClass))
                return false;
            if (!(a.Biology + a.BiologyClass).Equals(b.Biology + b.BiologyClass))
                return false;
            if (!(a.Politics + a.PoliticsClass).Equals(b.Politics + b.PoliticsClass))
                return false;
            if (!(a.History + a.HistoryClass).Equals(b.History + b.HistoryClass))
                return false;
            if (!(a.Geography + a.GeographyClass).Equals(b.Geography + b.GeographyClass))
                return false;
            if (!(a.Computer + a.ComputerClass).Equals(b.Computer + b.ComputerClass))
                return false;

            return true;
        }

        public void PrintGroupClass(string path)
        {
            try
            {
                HSSFWorkbook book = new HSSFWorkbook();
                ISheet sheet = book.CreateSheet("分班情况");
                IRow row0 = sheet.CreateRow(0);
                row0.CreateCell(0).SetCellValue("GroupID");
                row0.CreateCell(1).SetCellValue("语文");
                row0.CreateCell(2).SetCellValue("数学");
                row0.CreateCell(3).SetCellValue("英语");
                row0.CreateCell(4).SetCellValue("物理");
                row0.CreateCell(5).SetCellValue("化学");
                row0.CreateCell(6).SetCellValue("生物");
                row0.CreateCell(7).SetCellValue("政治");
                row0.CreateCell(8).SetCellValue("历史");
                row0.CreateCell(9).SetCellValue("地理");
                row0.CreateCell(10).SetCellValue("通技");
                row0.CreateCell(11).SetCellValue("人数");

                List<Student> listStudentInGroup = new List<Student>();
                List<CountStu> listAgain = new List<CountStu>();
                int id = 1;
                for (int i = 0; ; i++)
                {
                    listStudentInGroup.Clear();
                    listAgain.Clear();
                    foreach (Student s in StudentsDictionary.Values)
                    {
                        if (s.GroupId == i) listStudentInGroup.Add(s);

                    }
                    if (listStudentInGroup.Count == 0) break;

                    foreach(Student stu in listStudentInGroup){
                        bool flag = false;
                        foreach(CountStu s in listAgain)
                        {
                            if (checkStudent(s.student, stu) == true)
                            {
                                flag = true;
                                s.num++;
                                break;
                            }  
                        }
                        if (flag == false)
                        {
                            CountStu newone = new CountStu();
                            newone.student = stu;
                            newone.num = 1;
                            listAgain.Add(newone);
                        }
                    }

                    foreach(CountStu s in listAgain)
                    {
                        IRow row = sheet.CreateRow(id++);
                        row.CreateCell(0).SetCellValue(s.student.GroupId);
                        row.CreateCell(1).SetCellValue(s.student.ChineseName+s.student.ChineseClass);
                        row.CreateCell(2).SetCellValue(s.student.MathName+s.student.MathClass);
                        row.CreateCell(3).SetCellValue(s.student.EnglishName+ s.student.EnglishClass);
                        row.CreateCell(4).SetCellValue(s.student.PhysicsName+ (s.student.PhysicsName.Length>2?"":s.student.Physics) + s.student.PhysicsClass);
                        row.CreateCell(5).SetCellValue(s.student.ChemistryName + (s.student.ChemistryName.Length>2?"":s.student.Chemistry) + s.student.ChemistryClass);
                        row.CreateCell(6).SetCellValue(s.student.BiologyName + (s.student.BiologyName.Length>2?"":s.student.Biology) + s.student.BiologyClass);
                        row.CreateCell(7).SetCellValue(s.student.PoliticsName + (s.student.PoliticsName.Length>2?"":s.student.Politics) + s.student.PoliticsClass);
                        row.CreateCell(8).SetCellValue(s.student.HistoryName + (s.student.HistoryName.Length>2?"":s.student.History) + s.student.HistoryClass);
                        row.CreateCell(9).SetCellValue(s.student.GeographyName + (s.student.GeographyName.Length>2?"":s.student.Geography) + s.student.GeographyClass);
                        row.CreateCell(10).SetCellValue(s.student.ComputerName + (s.student.ComputerName.Length>2?"":s.student.Computer) + s.student.ComputerClass);
                        row.CreateCell(11).SetCellValue(s.num);
                    }

                }

                sheet = book.CreateSheet("学生明细");
                row0 = sheet.CreateRow(0);
                row0.CreateCell(0).SetCellValue("GroupID");
                row0.CreateCell(1).SetCellValue("学号");
                row0.CreateCell(2).SetCellValue("姓名");
                row0.CreateCell(3).SetCellValue("性别");
                row0.CreateCell(4).SetCellValue("语文");
                row0.CreateCell(5).SetCellValue("数学");
                row0.CreateCell(6).SetCellValue("英语");
                row0.CreateCell(7).SetCellValue("物理");
                row0.CreateCell(8).SetCellValue("化学");
                row0.CreateCell(9).SetCellValue("生物");
                row0.CreateCell(10).SetCellValue("政治");
                row0.CreateCell(11).SetCellValue("历史");
                row0.CreateCell(12).SetCellValue("地理");
                row0.CreateCell(13).SetCellValue("通技");
                row0.CreateCell(14).SetCellValue("语文150");
                row0.CreateCell(15).SetCellValue("数学150");
                row0.CreateCell(16).SetCellValue("英语150");
                row0.CreateCell(17).SetCellValue("选课300");
                row0.CreateCell(18).SetCellValue("总分750");
                row0.CreateCell(19).SetCellValue("名次");
                row0.CreateCell(20).SetCellValue("政治赋分");
                row0.CreateCell(21).SetCellValue("历史赋分");
                row0.CreateCell(22).SetCellValue("地理赋分");
                row0.CreateCell(23).SetCellValue("物理赋分");
                row0.CreateCell(24).SetCellValue("化学赋分");
                row0.CreateCell(25).SetCellValue("生物赋分");
                row0.CreateCell(26).SetCellValue("通技赋分");

                id =1;
                for (int i = 0; ; i++)
                {
                    listStudentInGroup.Clear();
                    foreach (Student s in StudentsDictionary.Values)
                    {
                        if (s.GroupId == i) listStudentInGroup.Add(s);

                    }
                    if (listStudentInGroup.Count == 0) break;

                    foreach (Student s in listStudentInGroup)
                    {
                        IRow row = sheet.CreateRow(id++);
                        row.CreateCell(0).SetCellValue(s.GroupId);
                        row.CreateCell(1).SetCellValue(s.Id);
                        row.CreateCell(2).SetCellValue(s.Name);
                        row.CreateCell(3).SetCellValue(s.Sex);
                        row.CreateCell(4).SetCellValue(s.ChineseName+ s.ChineseClass);
                        row.CreateCell(5).SetCellValue(s.MathName + s.MathClass);
                        row.CreateCell(6).SetCellValue(s.EnglishName + s.EnglishClass);
                        row.CreateCell(7).SetCellValue(s.PhysicsName + (s.PhysicsName.Length>2?"":s.Physics) + s.PhysicsClass);
                        row.CreateCell(8).SetCellValue(s.ChemistryName + (s.ChemistryName.Length>2?"":s.Chemistry) + s.ChemistryClass);
                        row.CreateCell(9).SetCellValue(s.BiologyName + (s.BiologyName.Length>2?"":s.Biology) + s.BiologyClass);
                        row.CreateCell(10).SetCellValue(s.PoliticsName +( s.PoliticsName.Length>2?"":s.Politics) + s.PoliticsClass);
                        row.CreateCell(11).SetCellValue(s.HistoryName + (s.HistoryName.Length>2?"":s.History) + s.HistoryClass);
                        row.CreateCell(12).SetCellValue(s.GeographyName + (s.GeographyName.Length>2?"":s.Geography) + s.GeographyClass);
                        row.CreateCell(13).SetCellValue(s.ComputerName + (s.ComputerName.Length>2?"":s.Computer) + s.ComputerClass);
                        row.CreateCell(14).SetCellValue(s.ChineseScore);
                        row.CreateCell(15).SetCellValue(s.MathScore);
                        row.CreateCell(16).SetCellValue(s.EnglishScore);
                        row.CreateCell(17).SetCellValue(s.ChooseScore);
                        row.CreateCell(18).SetCellValue(s.TotalScore);
                        row.CreateCell(19).SetCellValue(s.num);
                        row.CreateCell(20).SetCellValue(s.PoliticsScore);
                        row.CreateCell(21).SetCellValue(s.HistoryScore);
                        row.CreateCell(22).SetCellValue(s.GeographyScore);
                        row.CreateCell(23).SetCellValue(s.PhysicsScore);
                        row.CreateCell(24).SetCellValue(s.ChemistryScore);
                        row.CreateCell(25).SetCellValue(s.BiologyScore);
                        row.CreateCell(26).SetCellValue(s.ComputerScore);
                    }
                }

                FileStream file = new FileStream(path, FileMode.OpenOrCreate);
                book.Write(file);
                file.Flush();
                file.Close();

                //foreach (Student s in Students)
                //{
                //    if (checkStudent(s, StudentsDictionary[s.Id]) == false)
                //        Console.WriteLine(s.Id+" "+s.Name);

                //}
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

        public string[] HalfMixClass()
        {
            EachClassWithStudents ecws = new EachClassWithStudents();

            //physics
            ecws.type = "物理选";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Physics.Equals("选") && int.Parse(s.PhysicsClass) > 10 && int.Parse(s.PhysicsClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
            }

            ecws = new EachClassWithStudents();
            
            ecws.type = "物理学";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Physics.Equals("学") && int.Parse(s.PhysicsClass) > 10 && int.Parse(s.PhysicsClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
            }

            //chemistry
            ecws = new EachClassWithStudents();
            
            ecws.type = "化学选";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Chemistry.Equals("选") && int.Parse(s.ChemistryClass) > 10 && int.Parse(s.ChemistryClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {

                EachClassWithStudentsList.Add(ecws);
                ecws = null;
                
            }

            ecws = new EachClassWithStudents();
            
            ecws.type = "化学学";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Chemistry.Equals("学") && int.Parse(s.ChemistryClass) > 10 && int.Parse(s.ChemistryClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
                
            }
            //biology
            ecws = new EachClassWithStudents();
            
            ecws.type = "生物选";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Biology.Equals("选") && int.Parse(s.BiologyClass) > 10 && int.Parse(s.BiologyClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
            }

            ecws = new EachClassWithStudents();
            
            ecws.type = "生物学";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Biology.Equals("学") && int.Parse(s.BiologyClass) > 10 && int.Parse(s.BiologyClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
                
            }
            //politics

            ecws = new EachClassWithStudents();
            
            ecws.type = "政治选";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Politics.Equals("选") && int.Parse(s.PoliticsClass) > 10 && int.Parse(s.PoliticsClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
            }

            ecws = new EachClassWithStudents();
            
            ecws.type = "政治学";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Politics.Equals("学") && int.Parse(s.PoliticsClass) > 10 && int.Parse(s.PoliticsClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
               
            }
            //history
            ecws = new EachClassWithStudents();
            
            ecws.type = "历史选";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.History.Equals("选") && int.Parse(s.HistoryClass) > 10 && int.Parse(s.HistoryClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
               
            }

            ecws = new EachClassWithStudents();
            
            ecws.type = "历史学";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.History.Equals("学") && int.Parse(s.HistoryClass) > 10 && int.Parse(s.HistoryClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
               
            }
            //geography

            ecws = new EachClassWithStudents();
            
            ecws.type = "地理选";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Geography.Equals("选") && int.Parse(s.GeographyClass) > 10 && int.Parse(s.GeographyClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
                
            }

            ecws = new EachClassWithStudents();
            
            ecws.type = "地理学";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Geography.Equals("学") && int.Parse(s.GeographyClass) > 10 && int.Parse(s.GeographyClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
            }
            //computer

            ecws = new EachClassWithStudents();
            
            ecws.type = "通技选";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Computer.Equals("选") && int.Parse(s.ComputerClass) > 10 && int.Parse(s.ComputerClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
            }

            ecws = new EachClassWithStudents();
            
            ecws.type = "通技学";
            ecws.student = new List<Student>();
            foreach (Student s in Students)
            {
                if (s.Computer.Equals("学") && int.Parse(s.ComputerClass) > 10 && int.Parse(s.ComputerClass) < 20)
                {
                    ecws.student.Add(s);
                }
            }
            if (ecws.student.Count != 0)
            {
                EachClassWithStudentsList.Add(ecws);
                ecws = null;
            }

            Console.WriteLine("编号  课程   人数");
            for (int i = 0; i < EachClassWithStudentsList.Count; i++)
            {
                Console.WriteLine(i+"  "+EachClassWithStudentsList[i].type+"  "+EachClassWithStudentsList[i].student.Count);
            }
            string ip1 = Console.ReadLine();
            string ip2 = Console.ReadLine();
            int id1 = int.Parse(ip1);
            int id2 = int.Parse(ip2);

            //抽取两者交集 
            List<Student> BothInStudents = new List<Student>();
            foreach (Student s in EachClassWithStudentsList[id1].student)
            {
                if (EachClassWithStudentsList[id2].student.Contains(s))
                    BothInStudents.Add(s);
            }
            Console.WriteLine("交集人数："+BothInStudents.Count);

            if (BothInStudents.Count != 0)
            {
                int allsum = BothInStudents.Count;
                int num = allsum / Classes.MaxInAClass;
                if (allsum % Classes.MaxInAClass != 0)
                    num++;
                int n = num;
                List<int> groupnumList = new List<int>();
                for (; num > 0; num--)
                {
                    groupnumList.Add(allsum / num);
                    allsum -= allsum / num;
                }
                for (int i = 0, j = 0; i < BothInStudents.Count; i++)
                {
                    if (groupnumList[j] == 0)
                        j++;
                    if (EachClassWithStudentsList[id1].type.Contains("通技"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].ComputerClass = (21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].ComputerName +="_"+EachClassWithStudentsList[id2].type;
                    }
                    else if (EachClassWithStudentsList[id1].type.Contains("地理"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].GeographyClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].GeographyName +="_" + EachClassWithStudentsList[id2].type;
                    }
                    else if (EachClassWithStudentsList[id1].type.Contains("历史"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].HistoryClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].HistoryName += "_" + EachClassWithStudentsList[id2].type;
                    }
                    else if (EachClassWithStudentsList[id1].type.Contains("政治"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].PoliticsClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].PoliticsName += "_" + EachClassWithStudentsList[id2].type;
                    }
                    else if (EachClassWithStudentsList[id1].type.Contains("生物"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].BiologyClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].BiologyName += "_" + EachClassWithStudentsList[id2].type;
                    }
                    else if (EachClassWithStudentsList[id1].type.Contains("化学"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].ChemistryClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].ChemistryName +="_" + EachClassWithStudentsList[id2].type;
                    }
                    else if (EachClassWithStudentsList[id1].type.Contains("物理"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].PhysicsClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].PhysicsName += "_" + EachClassWithStudentsList[id2].type;
                    }
                    //////

                    if (EachClassWithStudentsList[id2].type.Contains("通技"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].ComputerClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].ComputerName +="_" + EachClassWithStudentsList[id1].type;
                    }
                    else if (EachClassWithStudentsList[id2].type.Contains("地理"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].GeographyClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].GeographyName +="_" + EachClassWithStudentsList[id1].type;
                    }
                    else if (EachClassWithStudentsList[id2].type.Contains("历史"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].HistoryClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].HistoryName +="_" + EachClassWithStudentsList[id1].type;
                    }
                    else if (EachClassWithStudentsList[id2].type.Contains("政治"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].PoliticsClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].PoliticsName +="_" + EachClassWithStudentsList[id1].type;
                    }
                    else if (EachClassWithStudentsList[id2].type.Contains("生物"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].BiologyClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].BiologyName +="_" + EachClassWithStudentsList[id1].type;
                    }
                    else if (EachClassWithStudentsList[id2].type.Contains("化学"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].ChemistryClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].ChemistryName += "_" + EachClassWithStudentsList[id1].type;
                    }
                    else if (EachClassWithStudentsList[id2].type.Contains("物理"))
                    {
                        StudentsDictionary[BothInStudents[i].Id].PhysicsClass = '_'+(21 + j).ToString();
                        StudentsDictionary[BothInStudents[i].Id].PhysicsName +="_" + EachClassWithStudentsList[id2].type;
                    }

                    groupnumList[j]--;
                }
            }
            PrintGroupClass("IO/Group班级.xls");
            return new[] { EachClassWithStudentsList[id1].type, EachClassWithStudentsList[id2].type };
        }

    }
}
